//
//  MainViewController.swift
//  Weibo
//
//  Created by Jet on 16/5/4.
//  Copyright © 2016年 Jet. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    // MARK: -  compose点击响应方法
   @objc private func composeDidClick() {
        print(#function)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let mainTabBar = MainTabBar()
        //tabBar是只读的，不能够直接操作，所以要修改　可以用KVC的方式操作
       self.setValue(mainTabBar, forKey: "tabBar")
        
      //创建点击事件
       mainTabBar.composeBtn.addTarget(self, action: #selector(MainViewController.composeDidClick), forControlEvents: UIControlEvents.TouchUpInside)
        
       self.addChildViewControllers()

    }

    /**
     添加子视图控制器
     */
    private func addChildViewControllers(){
        
        self.addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        self.addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        self.addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        self.addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
   
    private func addChildViewController(VC: UIViewController,title:String,imageName:String) {
        
        
        //实例化导航视图控制器
        let nav = UINavigationController(rootViewController: VC)
        
        VC.title = title
        VC.tabBarItem.image = UIImage(named: imageName)
        //设置tabBarItem的颜色
        self.tabBar.tintColor = UIColor.orangeColor()
        
        //设置tabBarItem的颜色
//        VC.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        VC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        
        addChildViewController(nav)
        
    }

        override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
